package com.neusoft.a312cxy.android18cxy.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.neusoft.a312cxy.android18cxy.Listener.ShaiTuListListener;
import com.neusoft.a312cxy.android18cxy.R;
import com.neusoft.a312cxy.android18cxy.activity.AddpicActivity;
import com.neusoft.a312cxy.android18cxy.adapter.ShaiTuAdapter;
import com.neusoft.a312cxy.android18cxy.bean.ShaiTuListBean;
import com.neusoft.a312cxy.android18cxy.model.ShaiTuModel;

import java.util.List;

/**
 * Created by Young on 2017/9/25.
 */

public class ShaiTuFragment extends Fragment implements ShaiTuListListener {
    private RecyclerView recyclerView;
    List<ShaiTuListBean> list;
    private Button addpic;
    private int userid;
 //   private Context mContext;//承载上下文

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        View view=inflater.inflate(R.layout.fragment_post, container, false);
        initRecyclerView(view);
        ShaiTuModel model=new ShaiTuModel();
        model.getList("45",1,this);
        return  view;
    }

    public  void initRecyclerView(View view){
        addpic=(Button)view.findViewById(R.id.addpic);
        addpic.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                //Intent intent =new Intent(mContext, AddpicActivity.class);
               // Bundle bundle = new Bundle();
              //  bundle.putInt("id",entity.getId());
              //  intent.putExtras(bundle);
               // mContext.startActivity(intent);
                Intent intent=new Intent(getActivity(),AddpicActivity.class);
                intent.putExtra("userid",userid);
                startActivity(intent);
            }
        });
        recyclerView= (RecyclerView) view.findViewById(R.id.ac);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }

    @Override
    public void onResponse(List<ShaiTuListBean> listBeen) {
        list=listBeen;
        recyclerView.setAdapter(new ShaiTuAdapter(getActivity(),list));
    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(getActivity(), ""+msg, Toast.LENGTH_SHORT).show();
    }
}